package org.zsl.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zsl.dao.ProductMapper;
import org.zsl.model.Product;
import org.zsl.model.ResponseMessage;

import java.util.List;

@Service
public class ProductService {

    @Autowired
    private ProductMapper productMapper;

    public List<Product> getList(){

        return  productMapper.selectAll();
    }

    public ResponseMessage add(Product product){
        ResponseMessage responseMessage = new ResponseMessage();
        Boolean flag = productMapper.insert(product)>0;
        responseMessage.setSuccess(flag);
        return  responseMessage;
    }


    public ResponseMessage edit(Product product){

         if(product.getProductId()==-1){
             return  this.add(product);
         }else {
            return this.update(product);
         }
    }


    public ResponseMessage update(Product product){

        ResponseMessage responseMessage = new ResponseMessage();
        Boolean flag = productMapper.update(product)>0;
        responseMessage.setSuccess(flag);
        return  responseMessage;
    }

    public List<Product> getListByExample(Product product) {
        /**
         *  1.根据名称和价格查询数据
         *  2. 不定查询
         *      如果名称为空 ,就不计入查询条件
         *      如果价格为空, 就不计入查询条件
         * */


        return  null;
    }
}
